﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using FarseerPhysics.Collision;
using FarseerPhysics.Collision.Shapes;
using Somnus.Utils;
using Somnus.Core;
using FarseerPhysics.Dynamics.Contacts;
using Somnus.Objects.GameObjects.LevelObjects;


namespace Somnus.Objects.GameObjects
{
    class Character : PhysicsObject
    {
        /// <summary>
        /// Booleana que diz se o jogador está ou não no chão.
        /// </summary>
        private bool _onGround;



        public Character(DreamWorld world, String name, Texture2D texture, Nullable<Rectangle> sourceRectangle, float depth, Boolean isStatic, float x, float y, float width, float height, float rotation)
            : base(world, name, texture, sourceRectangle, depth, isStatic, x, y, width, height, rotation)
        {
        }

        public override bool HandleBeginContact(Fixture thisFixture, Fixture otherFixture, Contact contact)
        {
            if (otherFixture.UserData is Platform)
            {
                _onGround = true;
                this.Rotation = (otherFixture.UserData as PhysicsObject).Rotation;
            }
            
            return base.HandleBeginContact(thisFixture, otherFixture, contact);
        }

        public override void HandleEndContact(Fixture thisFixture, Fixture otherFixture)
        {
            if (otherFixture.UserData is Platform)
            {
                _onGround = false;
                
            }
            
            base.HandleEndContact(thisFixture, otherFixture);
        }

        public bool onGround
        {
            get
            {
                return _onGround;
            }
        }
    }
}
